﻿Public Class ISCPacketHandler

    Public handler As ISCHandler

    Public Sub New(ByVal handler As ISCHandler)
        Me.handler = handler
    End Sub

    Public Sub handlePacket(ByVal buf() As Byte, ByVal index As Integer, ByVal len As Integer)
        Dim header As Integer = buf(index)
        Select Case header
            Case &H1
                addChannel(buf, index + 4)
                Exit Select
            Case Else
                log.log(LogType.MSG_ISC)
                log.log(LogType.MSG_RECV)
                For i As Integer = 0 To len - 1 Step i + 1
                    Console.Write("{0:x2} ", buf(i + index))
                Next
                Console.WriteLine()
                Exit Select
        End Select
    End Sub

    Public Sub addChannel(ByVal buf() As Byte, ByVal index As Integer)
        If (ISCPacketCreator.getString(buf, index) = "WorldServer") Then
            handler.place = ISC.channels.Count
            ISC.channels.Add(handler.place)
            LoginServer.updateCluster()
            log.log(LogType.MSG_INFO, "New Channel Connected")
            ISCHandler.ISCHandlers.Add(handler)
        End If
    End Sub

End Class